package com.maixy.studyonlineapi.controller;

import com.maixy.studyonlineapi.apis.ApiController;
import com.maixy.studyonlineapi.apis.ApiRequest;
import com.maixy.studyonlineapi.apis.ApiResponse;
import com.maixy.studyonlineapi.exceptions.MissParamException;
import com.maixy.studyonlineapi.service.MediaService;
import com.maixy.studyonlineapi.view.MediaView;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName MediaController
 * @Description TODO
 * @Date 2020/11/28 21:48
 * @Author maixy
 */
@RestController
@RequestMapping("/v1/media")
public class MediaController extends ApiController {

    @Resource
    private MediaService mediaService;

    /**
     * loginAvatar
     *
     * @param request --userName 用户名
     * @return --
     */
    public ApiResponse loginAvatar(ApiRequest request) {
        String userName = request.getDataParamAsString("userName");

        if (StringUtils.isBlank(userName)) {
            throw new MissParamException();
        }

        MediaView mediaView = mediaService.loginAvatar(userName);
        return ApiResponse.ok()
                .addValueToData("mediaView", mediaView);
    }
}
